﻿Public Class frmLogin

    Function LoginUser() As Boolean
        Dim username As String = txtUserName.Text
        Dim password As String = txtPassword.Text
        Dim sql As String = String.Format("exec usp_DangNhap '{0}', '{1}'", username, password)
        Dim dt As DataTable = DataProvider.LoadTable(sql)

        If dt.Rows.Count = 0 Then
            If MessageBox.Show("Username hoặc password không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error) = MsgBoxResult.Retry Then
                LoginUser()
            End If
            Return False
        End If
        ' Đến lúc này xem như đã đăng nhập thành công
        Dim dr As DataRow = dt.Rows(0)
        USER.USERName = username
        USER.MaCV = dr("MACV")
        USER.Password = password
        USER.IsLogin = True
        Return True
    End Function
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        If LoginUser() Then
            'Dim f As New Form1()
            ''me.Hide
            'f.ShowDialog()
            Me.Close()
        End If
    End Sub
    Private Sub frmLogin_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnLogin_Click(sender, e)
        End If
    End Sub
End Class